<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="算法,">










<meta name="description" content="内容 数组去复 实现一个洗牌算法 计算数组中每个元素出现的次数 JS找出数组 arr 中重复出现过的元素 统计一个字符串中出现最多的字母 字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。) 不利用第三方变量的情况下交换两个变量的值  数组去重复方法一 正常思维123456789101112var array=[1,1,&amp;apos;1&amp;">
<meta name="keywords" content="算法">
<meta property="og:type" content="article">
<meta property="og:title" content="前端常见算法">
<meta property="og:url" content="http://blog.xiaowuzi.info/2018/04/07/前端常见算法/index.html">
<meta property="og:site_name" content="小武子博客">
<meta property="og:description" content="内容 数组去复 实现一个洗牌算法 计算数组中每个元素出现的次数 JS找出数组 arr 中重复出现过的元素 统计一个字符串中出现最多的字母 字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。) 不利用第三方变量的情况下交换两个变量的值  数组去重复方法一 正常思维123456789101112var array=[1,1,&amp;apos;1&amp;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-04-13T07:05:41.295Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="前端常见算法">
<meta name="twitter:description" content="内容 数组去复 实现一个洗牌算法 计算数组中每个元素出现的次数 JS找出数组 arr 中重复出现过的元素 统计一个字符串中出现最多的字母 字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。) 不利用第三方变量的情况下交换两个变量的值  数组去重复方法一 正常思维123456789101112var array=[1,1,&amp;apos;1&amp;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://blog.xiaowuzi.info/2018/04/07/前端常见算法/">





  <title>前端常见算法 | 小武子博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小武子博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.xiaowuzi.info/2018/04/07/前端常见算法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tony">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小武子博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">前端常见算法</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-07T21:11:35+08:00">
                2018-04-07
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/算法/" itemprop="url" rel="index">
                    <span itemprop="name">算法</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="内容"><a href="#内容" class="headerlink" title="内容"></a>内容</h2><ul>
<li>数组去复</li>
<li>实现一个洗牌算法</li>
<li>计算数组中每个元素出现的次数</li>
<li>JS找出数组 arr 中重复出现过的元素</li>
<li>统计一个字符串中出现最多的字母</li>
<li>字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。)</li>
<li>不利用第三方变量的情况下交换两个变量的值</li>
</ul>
<h3 id="数组去重复"><a href="#数组去重复" class="headerlink" title="数组去重复"></a>数组去重复</h3><p>方法一 正常思维<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">var array=[1,1,&apos;1&apos;];</span><br><span class="line"></span><br><span class="line">function unique(array)&#123;</span><br><span class="line">    var res=[];</span><br><span class="line">    for(var i=0,len=array.length;i&lt;len;i++)&#123;</span><br><span class="line">        var current=array[i];</span><br><span class="line">        if(res.indexOf(current)===-1) res.push(current);</span><br><span class="line">    &#125;</span><br><span class="line">    return res;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">console.log(unique(array));</span><br></pre></td></tr></table></figure></p>
<a id="more"></a>
<p>方法二、利用filter</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var array=[1,2,1,1,&apos;1&apos;];</span><br><span class="line"></span><br><span class="line">function unique(array)&#123;</span><br><span class="line">    var res=array.filter(function(item,index,array)&#123;</span><br><span class="line">        return array.indexOf(item)===index;</span><br><span class="line">    &#125;);</span><br><span class="line">    return res;</span><br><span class="line">&#125;</span><br><span class="line">console.log(unique(array));</span><br></pre></td></tr></table></figure>
<p>方法三、使用reduce</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">var arr=[1,2,1,2,3,5,4,5,3,4,4,4,4];</span><br><span class="line">function unique()&#123;</span><br><span class="line">    var result=arr.sort().reduce((init,current)=&gt;&#123;</span><br><span class="line">        if(init.length===0 || init[init,length-1])&#123;</span><br><span class="line">            init.push(current);</span><br><span class="line">        &#125;</span><br><span class="line">        return init;</span><br><span class="line">    &#125;,[]);</span><br><span class="line">    return result;</span><br><span class="line">&#125;</span><br><span class="line">console.log(unique(arr));</span><br></pre></td></tr></table></figure>
<h3 id="洗牌算法"><a href="#洗牌算法" class="headerlink" title="洗牌算法"></a>洗牌算法</h3><h4 id="算法描述"><a href="#算法描述" class="headerlink" title="算法描述"></a>算法描述</h4><blockquote>
<p>这是最经典的洗牌算法，其算法思想是从原数组中随机抽取一个新的元素到新数组中<br>从还没处理的数组（假如还剩n个）中，产生一个[0,n]之间的随机数random<br>从剩下的n个元素中把第random个元素取出到新数组中<br>删除原数组第random个元素<br>重复第2 3步直到所有的元素取完</p>
</blockquote>
<h4 id="代码实现"><a href="#代码实现" class="headerlink" title="代码实现"></a>代码实现</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">function shufle(arr)&#123;</span><br><span class="line">	var result=[],</span><br><span class="line">		random;</span><br><span class="line">		while(arr.length&gt;0)&#123;</span><br><span class="line">			random=Math.floor(Math.random(arr.length));</span><br><span class="line">			result.push(arr[random]);</span><br><span class="line">			arr.splice(random,1);</span><br><span class="line">		&#125;</span><br><span class="line">		return result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="计算数组中每个元素出现的次数"><a href="#计算数组中每个元素出现的次数" class="headerlink" title="计算数组中每个元素出现的次数"></a>计算数组中每个元素出现的次数</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">var names=[&apos;Alice&apos;,&apos;Bob&apos;,&apos;Iiff&apos;,&apos;Bruce&apos;,&apos;Alice&apos;];</span><br><span class="line"></span><br><span class="line">var countedNames=names.reduce(function(allNames,name)&#123;</span><br><span class="line">    if(name in allNames)&#123;</span><br><span class="line">        allNames[name]++;</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">        allNames[name]=1;</span><br><span class="line">    &#125;</span><br><span class="line">    return allNames;</span><br><span class="line">&#125;,&#123;&#125;);</span><br></pre></td></tr></table></figure>
<h3 id="JS找出数组-arr-中重复出现过的元素"><a href="#JS找出数组-arr-中重复出现过的元素" class="headerlink" title="JS找出数组 arr 中重复出现过的元素"></a>JS找出数组 arr 中重复出现过的元素</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">var str1 = &quot;jhadfgskjfajhdewqe&quot;;</span><br><span class="line">var arr1=str1.split(&apos;&apos;);</span><br><span class="line">var result=arr1.reduce(function(arr2,current)&#123;</span><br><span class="line">	if(arr1.indexOf(current)&gt;-1 &amp;&amp; ((arr2.length===0) || (arr2.length !==0 &amp;&amp; arr2.indexOf(current)===-1))) arr2.push(current);</span><br><span class="line">	return arr2;</span><br><span class="line">&#125;,[]);</span><br><span class="line">console.log(str1);</span><br></pre></td></tr></table></figure>
<h3 id="统计一个字符串中出现最多的字母"><a href="#统计一个字符串中出现最多的字母" class="headerlink" title="统计一个字符串中出现最多的字母"></a>统计一个字符串中出现最多的字母</h3><p>方法一</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">var str1 = &quot;jhadfgskjfajhdewqe&quot;;  </span><br><span class="line">    var arr1 = str1.split(&apos;&apos;);  </span><br><span class="line">    console.log(arr1);  </span><br><span class="line">    function MostUnit()&#123;  </span><br><span class="line">        var arrA = [];  </span><br><span class="line">        var arrB = [];  </span><br><span class="line">        for(var i = 0 ;i &lt;arr1.length; i ++)&#123;  </span><br><span class="line">            if(arrA.indexOf(arr1[i])==-1)&#123;  </span><br><span class="line">                arrA.push(arr1[i]);  </span><br><span class="line">                arrB.push(1);  </span><br><span class="line">            &#125;else &#123;  </span><br><span class="line">                arrB[arrA.indexOf(arr1[i])] ++;  </span><br><span class="line">            &#125;  </span><br><span class="line">        &#125;  </span><br><span class="line">        console.log(arrB)  </span><br><span class="line">        console.log(arrA[arrB.indexOf(Math.max.apply(Math,arrB))]);  </span><br><span class="line">    &#125;  </span><br><span class="line">    MostUnit();//j</span><br></pre></td></tr></table></figure>
<p>方法二</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">var str1 = &quot;jhadfgskjfajhdewqe&quot;;</span><br><span class="line">var result=str1.split(&apos;&apos;).reduce(function(obj,current)&#123;</span><br><span class="line">	if(current in obj)&#123;</span><br><span class="line">		obj[current]++;</span><br><span class="line">	&#125;else&#123;</span><br><span class="line">		obj[current]=1;</span><br><span class="line">	&#125;</span><br><span class="line">	obj.max=obj.max&gt;obj[current]?obj.max:obj[current];</span><br><span class="line">	obj.key=obj.max&gt;obj[current]?obj.key:current;</span><br><span class="line">	return obj;</span><br><span class="line">&#125;,&#123;&#125;);</span><br><span class="line">console.log(result.key,result.max);</span><br></pre></td></tr></table></figure>
<h3 id="字符串回文判断-回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。"><a href="#字符串回文判断-回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。" class="headerlink" title="字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。)"></a>字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">var str1=&apos;abcdefgh&apos;;</span><br><span class="line">var str1=&apos;abcdcba&apos;;</span><br><span class="line">function plalindrome(str)&#123;</span><br><span class="line">    return str===str.split(&apos;&apos;).reverse().join(&apos;&apos;);</span><br><span class="line">&#125;</span><br><span class="line">console.log(plalindrome(str1)); //false;</span><br><span class="line">console.log(plalindrome(str2)); //true;</span><br></pre></td></tr></table></figure>
<h3 id="不利用第三方变量的情况下交换两个变量的值"><a href="#不利用第三方变量的情况下交换两个变量的值" class="headerlink" title="不利用第三方变量的情况下交换两个变量的值"></a>不利用第三方变量的情况下交换两个变量的值</h3><p>方法一</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var a = 10;  </span><br><span class="line">var b = 12;  </span><br><span class="line">function swap (a,b) &#123;  </span><br><span class="line">    b = b - a;  </span><br><span class="line">    a = a + b;  </span><br><span class="line">    b = a - b;  </span><br><span class="line">    return [a,b]  </span><br><span class="line">&#125;  </span><br><span class="line">console.log(swap(a,b));</span><br></pre></td></tr></table></figure>
<p>方法二</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">a = &#123;a:b,b:a&#125;;</span><br><span class="line">b = a.b;</span><br><span class="line">a = a.a;</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center">
  <div>Donate comment here</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Tony 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Tony 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/算法/" rel="tag"># 算法</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/04/07/排序算法/" rel="next" title="排序算法">
                <i class="fa fa-chevron-left"></i> 排序算法
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/08/比较运算符面试题/" rel="prev" title="比较运算符面试题">
                比较运算符面试题 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Tony</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">65</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#内容"><span class="nav-number">1.</span> <span class="nav-text">内容</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#数组去重复"><span class="nav-number">1.1.</span> <span class="nav-text">数组去重复</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#洗牌算法"><span class="nav-number">1.2.</span> <span class="nav-text">洗牌算法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#算法描述"><span class="nav-number">1.2.1.</span> <span class="nav-text">算法描述</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#代码实现"><span class="nav-number">1.2.2.</span> <span class="nav-text">代码实现</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#计算数组中每个元素出现的次数"><span class="nav-number">1.3.</span> <span class="nav-text">计算数组中每个元素出现的次数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JS找出数组-arr-中重复出现过的元素"><span class="nav-number">1.4.</span> <span class="nav-text">JS找出数组 arr 中重复出现过的元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#统计一个字符串中出现最多的字母"><span class="nav-number">1.5.</span> <span class="nav-text">统计一个字符串中出现最多的字母</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符串回文判断-回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。"><span class="nav-number">1.6.</span> <span class="nav-text">字符串回文判断(回文是指把相同的词汇或句子，在下文中调换位置或颠倒过来，产生首尾回环的情趣，叫做回文，也叫回环。)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#不利用第三方变量的情况下交换两个变量的值"><span class="nav-number">1.7.</span> <span class="nav-text">不利用第三方变量的情况下交换两个变量的值</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tony</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>